#ifndef CHATWIDGET_H
#define CHATWIDGET_H

#include "ChatMessageModel.h"
#include "ChatMessageDelegate.h"
#include "CustomButton.h"
#include "SettingWidget.h"

#include <QWidget>
#include <QPainter>
#include <QTextEdit>
#include <QPushButton>
#include <QListView>

class ChatWidget : public QWidget
{
    Q_OBJECT
public:
    explicit ChatWidget(QWidget *parent = nullptr);
    void init();
    void setClientIP(QString clientIP);
    void setClientName(QString clientName);
    void addMessage(const ChatMessageModel::ChatMessage &message);

protected:
    void paintEvent(QPaintEvent *event) override;

public slots:
    void getFilePath();

signals:
    void singal_SendMessage(QString &targetIP,QString &messageData);
    void singal_SendFile(QString &targetIP,QString filePath);
    void signal_UpdateFilePath(QString filePath);
private:
    QString m_ClientIP = "10.1.32.248";
    QString m_ClientName = "张三";

    QTextEdit* m_TextEdit;
    QPushButton* m_SendButton;
    CustomButton* m_FileButton;
    CustomButton* m_SettingButton;
    SettingWidget* m_SettingWidget;

    QListView *m_chatView;            // 聊天记录视图
    ChatMessageModel *m_chatModel;     // 数据模型
    ChatMessageDelegate *m_delegate;   // 绘制代理


    void drawTitle(QPainter& painter);
};

#endif // CHATWIDGET_H
